package com.jrapider.om;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by Administrator on 2018/11/20.
 */
public class JSONResult {
    public static final int SUCCESS = 1;
    public static final int FAIL = -1;

    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder {
        private JSONObject result;

        public Builder() {
            this.result = new JSONObject();
        }

        public Builder setCode(int code) {
            result.put("code", code);
            return this;
        }
        public Builder setData(Object data) {
            result.put("data", data);
            return this;
        }
        public Builder setRows(Object data) {
            result.put("rows", data);
            return this;
        }
        public Builder setCount(Object data) {
            result.put("count", data);
            return this;
        }
        public Builder setMsg(Object data) {
            result.put("msg", data);
            return this;
        }
        public Builder put(String key, Object data) {
            result.put(key, data);
            return this;
        }
        public Builder success(String msg) {
            setCode(SUCCESS);
            setMsg(msg);
            return this;
        }
        public Builder fail(String msg) {
            setCode(FAIL);
            setMsg(msg);
            return this;
        }

        public JSONObject build() {
            return result;
        }
    }
}
